﻿using Newtonsoft.Json;
using System;

namespace Ymatou.API.Common
{
    /// <summary>
    /// API接口返回的通用类
    /// 所有返回数据，都在这个类里面
    /// </summary>
    public class BaseResponseModel<T> where T : IResponse
    {
        /// <summary>
        /// 基础响应模型
        /// </summary>
        public BaseResponseModel()
        {
            RetData = default(T);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="status"></param>
        /// <param name="msg"></param>
        public BaseResponseModel(ResultStatus status, String msg)
        {
            this.RetCode = (int)status;
            this.RetMsg = msg;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="status"></param>
        /// <param name="bizCode">业务类型Code</param>
        /// <param name="msg"></param>
        public BaseResponseModel(ResultStatus status, int bizCode, String msg)
        {
            this.RetCode = (int) status;
            this.RetMsg = msg;
            this.RetBizCode = bizCode;
        }

        /// <summary>
        /// 基础响应模型
        /// </summary>
        /// <param name="status"></param>
        /// <param name="msg"></param>
        /// <param name="result"></param>
        public BaseResponseModel(ResultStatus status, String msg, T result)
        {
            this.RetCode = (int)status;
            this.RetMsg = msg;
            this.RetData = result;
        }
        /// <summary>
        /// 返回响应代码	Code	
        /// </summary>
        [JsonProperty("Code")]
        public Int32 RetCode { get; set; }
        /// <summary>
        /// 返回的业务类型Code	
        /// </summary>
        [JsonProperty("BCode")]
        public Int32 RetBizCode { get; set; }
        /// <summary>
        /// 返回响应消息	Msg
        /// </summary>
        [JsonProperty("Msg")]
        public String RetMsg { get; set; }
        /// <summary>
        /// 返回的数据模型
        /// </summary>
        [JsonProperty("Data")]
        public T RetData { get; set; }

        /// <summary>
        /// 若服务支持表示服务的跟踪信息
        /// </summary>
        public Trace Trace { get; set; }
    }

    /// <summary>
    ///  操作成功
    /// </summary>
    public class SuccessResponseModel<T>: BaseResponseModel<T> where T : IResponse
    {
        /// <summary>
        /// 
        /// </summary>
        public SuccessResponseModel()
            : this(null)
        {
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="result"></param>
        public SuccessResponseModel(T result)
            : base(ResultStatus.Success, "", result)
        {
        }
    }
    /// <summary>
    ///  业务错误，返回
    /// </summary>
    public class BussniessErrorResponseModel<T>: BaseResponseModel<T> where T : IResponse
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="retMsg"></param>
        public BussniessErrorResponseModel(String retMsg)
            : base(ResultStatus.BussniessError, retMsg)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="bizCode"></param>
        /// <param name="retMsg"></param>
        public BussniessErrorResponseModel(int bizCode, String retMsg)
            : base(ResultStatus.BussniessError, bizCode, retMsg)
        {
        }
    }
    /// <summary>
    ///  参数错误，返回
    /// </summary>
    public class ParameterErrorResponseModel<T> : BaseResponseModel<T> where T : IResponse
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="retMsg"></param>
        public ParameterErrorResponseModel(String retMsg)
            : base(ResultStatus.ParameterError, retMsg)
        {
        }
    }
    /// <summary>
    ///  系统错误，返回
    /// </summary>
    public class SystemErrorResponseModel<T> : BaseResponseModel<T> where T : IResponse
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="retMsg"></param>
        public SystemErrorResponseModel(String retMsg)
            : base(ResultStatus.SystemError, retMsg)
        {
        }
    }
}